using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BlogEngine.Core.Providers;
using BlogEngine.Core;

public partial class gallery_addphoto : System.Web.UI.Page
{
	protected Guid guid;

	protected void Page_Load(object sender, EventArgs e)
	{
		guid = new Guid(Request.QueryString["AlbumId"]);

		Page.Title = Resources.labels.photos;

		btnImportFile.Click += new EventHandler(btnImportFile_Click);
	}

	#region Event Handlers

	/// <summary>
	/// Imports all the files in the import directory
	/// </summary>
	private void btnImportFile_Click(object sender, EventArgs e)
	{
		if (!Page.IsValid)
			throw new InvalidOperationException("One or more validators are invalid.");

		if (!FileUpload1.HasFile)
			throw new InvalidOperationException("No file was uploaded.");

		Photo photo = new Photo();
		photo.Album = Album.GetById(guid);
		photo.Title = txtTitle.Text.Trim();
		photo.Description = txtDescription.Text.Trim();
		photo.IsPublished = true;
		photo.TagString = txtTags.Text;

		if (!photo.Import(FileUpload1.PostedFile.InputStream,FileUpload1.FileName))
			throw new InvalidOperationException("An error occurred during upload.");

		photo.Save();

		txtTitle.Text = "";
		txtDescription.Text = "";
		photo.IsPublished = true;
		txtTags.Text = "";

	}

	#endregion


}
